home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / telecom / 119 / c / cb.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-04-16  |  21.6 KB  |  734 lines

  1. /*  CB3.C - C Beautifier - Jim Kyle (76703,762) - 05/06/86
  2.  *      not mainstream rules, but I like 'em!!
  3.  */
  4.  
  5. /* port to Apollo Domain by Jinfu Chen (72327,2434) - 03/07/87 */
  6. /* port to Atari ST by Jinfu Chen                   - 03/08/87 */
  7.  
  8. /*#define CPM           / remove for MSDOS, include for CPM */
  9. /*#define APOLL O       / remove for Apollo Domain version */
  10. #define Megamax
  11.  
  12. /* ------------ *
  13.  * header files *
  14.  * ------------ */
  15. #ifdef CPM
  16. #include "libc.h"                 /* specifically, Aztec Cii V1.05c */
  17. #include "ctype.h"
  18. #else
  19. #ifdef MSDOS
  20. #include "stdio.h"                /* specifically, CI's C86 V1.33 */
  21. #define ishex(x) isdigit(x) || ( toupper(x) < 'G' && toupper(x) >= 'A')
  22. #else
  23. #ifdef APOLLO             /* specifically, Domain C Rev 4.16 */
  24. #include <ctype.h>
  25. #include <stdio.h>
  26. #define ishex(x) isdigit(x) || ( toupper(x) < 'G' && toupper(x) >= 'A')
  27. #else
  28. #ifdef Megamax             /* specifically, Megamax C Rev 1.1 */
  29. #include <ctype.h>
  30. #include <stdio.h>
  31. #include <osbind.h>
  32. #define ishex(x) isdigit(x) || ( toupper(x) < 'G' && toupper(x) >= 'A')
  33. #endif
  34.  
  35. #endif
  36.  
  37. /* ------------------ *
  38.  * symbolic constants *
  39.  * ------------------ */
  40. #define LINEW 78
  41. #define CMNTCOL 40
  42. #define MTAB 8
  43. #define LIND 2
  44. #define YES 1
  45. #define NO 0
  46.  
  47. /* ---------------- *
  48.  * global variables *
  49.  * ---------------- */
  50. char bfr [ 128 ];
  51. FILE * inf, * otf;
  52. int clvl = 0,
  53.     plvl = 1,
  54.     ilvl = 0,
  55.     ppilv = 0,
  56.     istk [ 64 ],
  57.     istkp = 0,
  58.     indf = 0,
  59.     cflg = 0,
  60.     dflg = 0,
  61.     iflg = 0,
  62.     tok = 0,
  63.     oldtok = 0,
  64.     mtabv = MTAB,
  65.     lnwv = LINEW,
  66.     lindv = LIND,
  67.     ccv = CMNTCOL,
  68.     nval = 0,
  69.     ln = 1,
  70.     col = 0;
  71.  
  72. main ( argc, argv ) int argc ;
  73. char * argv [];
  74. { if ( argc == 1 || * argv [ 1 ] == '?' )/* help summary */
  75.     { msg ( "\nCommand syntax is: CB [[<args>] [<file>]] <CR>\n" );
  76.       msg ( "  where <args> begins with '-' and is followed by\n" );
  77.       msg ( "\tCn - start comments at col n\n" );
  78.       msg ( "\tIn - each indent is n spaces\n" );
  79.       msg ( "\tNn - line number with increment n\n" );
  80.       msg ( "\tO<file> - output to <file> (must be last)\n" );
  81.       msg ( "\tTn - machine tabs are n cols apart\n" );
  82.       msg ( "\tWn - line length is n cols\n" );
  83.       msg ( "\tAny mix of args can follow the '-'; each one\n" );
  84.       msg ( "\t    takes effect immediately.\n" );
  85.       msg ( "  <file> is a full filespec; <CR> is RETURN or ENTER.\n" );
  86.       msg ( "  The [ and ] indicate options; don't type them.\n\n" );
  87.       msg ( "Default values of the settings are:\n" );
  88.       msg ( "\tC40 I2 N0 T8 W78\n" );
  89.       exit ( 0 );
  90.     }
  91.   otf = stdout;
  92.   while ( -- argc )                     /* let parsearg() do most */
  93.     parsearg ( *++ argv );
  94. }
  95.  
  96. char * dmpdgt ( fn )                    /* skip over digits */
  97. char * fn;
  98. { if ( isdigit ( * fn ))
  99.     { while ( isdigit ( * fn ))
  100.         ++ fn;
  101.       -- fn;
  102.     }
  103.   return ( fn );
  104. }
  105.  
  106. parsearg ( fn )                         /* process one arg */
  107. char * fn;
  108. { if ( * fn == '-' )                    /* is an argument */
  109.     while ( *++ fn )
  110.       { switch ( toupper ( * fn ))
  111.           {
  112.           case 'C' :
  113.             ccv = atoi ( ++ fn );       /* set comment column */
  114.             fn = dmpdgt ( fn );
  115.             break;
  116.  
  117.           case 'I' :
  118.             lindv = atoi ( ++ fn );     /* set indent width */
  119.             if ( lindv < 1 )
  120.               lindv = 1;
  121.             fn = dmpdgt ( fn );
  122.             break;
  123.  
  124.           case 'N' :
  125.             nval = atoi ( ++ fn );      /* set line number increment */
  126.             fn = dmpdgt ( fn );
  127.             break;
  128.  
  129.           case 'O' :
  130.             fclose ( otf );             /* write to file */
  131.             otf = fopen ( ++ fn, "w" );
  132.             msg ( "Writing output to: " );
  133.             msg ( fn );
  134.             tocrt ( '\n' );
  135.             lnwv = 32767;               /* never wrap to a file */
  136.             return;
  137.  
  138.           case 'T' :
  139.             mtabv = atoi ( ++ fn );     /* set mach tab spacing */
  140.             if ( mtabv < 1 )
  141.               mtabv = 1000;
  142.             fn = dmpdgt ( fn );
  143.             break;
  144.  
  145.           case 'W' :
  146.             lnwv = atoi ( ++ fn );      /* set line width */
  147.             fn = dmpdgt ( fn );
  148.             if ( lnwv < 1 )
  149.               lnwv = 32767;
  150.             break;
  151.  
  152.           default :
  153.             msg ( "Unknown arg: " );
  154.             tocrt ( * fn );
  155.             tocrt ( '\n' );
  156.           }
  157.       }
  158.   else                                  /* treat as filename */
  159.     {
  160.       if ( nval )
  161.         lnwv -= mtabv;
  162.       dofil ( fn );
  163.       if ( nval )
  164.         lnwv += mtabv;
  165.     }
  166. }
  167.  
  168. dofil ( fn )                            /* process one file */
  169. char * fn;
  170. { int loop ,
  171.      svtok;
  172.   if ( ! ( inf = fopen ( fn, "r" )))    /* open the file */
  173.     { msg ( "can't open " );
  174.       msg ( fn );
  175.       tocrt ( '\n' );
  176.       return;
  177.     }
  178.   col = clvl = oldtok = 0;              /* initialize globals */
  179.   ln = 1;
  180.   if ( nval )                           /* output line number */
  181.     outf ( ln * nval );
  182.   outb ( '/' );                         /* fake out C86 quirk */
  183.   outs ( "*  " );
  184.   outs ( fn );
  185.   outs ( " as formatted by CB.C\t*" );
  186.   outb ( '/' );
  187.   nl ();
  188.   for ( loop = 1; loop; oldtok = tok )  /* main loop */
  189.     { tok = gtok ( inf );               /* get next token */
  190.       if ( oldtok == ';'
  191.             && tok != ' '
  192.             && col )                    /* break after statement */
  193.         outb ( '\n' );
  194.       switch ( tok )                    /* special processing */
  195.         {
  196.         case 0 :                        /* newline or comment */
  197.           if ( clvl && ! iflg )
  198.             tok = oldtok;               /* ignore it outside condx */
  199.           else
  200.             if ( iflg || ! oldtok )
  201.               { nl ();
  202.                 if ( iflg )
  203.                   ind ( ilvl + 2 );
  204.                 tok = ' ';
  205.               }
  206.           continue;
  207.  
  208.         case ' ' :                      /* blank */
  209.           tok = oldtok;
  210.           continue;
  211.  
  212.         case EOF  :                     /* end of input */
  213.           loop = 0;
  214.           continue;
  215.  
  216.         case '{' :                      /* begin compound */
  217.           if ( col )
  218.             nl ();
  219.           ind ( ilvl ++ );              /* push ilvl in */
  220.           ++ clvl;
  221.           outs ( bfr );
  222.           tok = ' ';
  223.           continue;
  224.  
  225.         case '}' :                      /* end compound */
  226.           if ( col )
  227.             nl ();
  228.           if ( ilvl )
  229.             -- ilvl;                    /* pop ilvl out for c.s. */
  230.           ind ( ilvl );
  231.           outs ( bfr );
  232.           nl ();
  233.           if ( iflg )
  234.             iflg = 0;
  235.           -- clvl;
  236.           popilvl ();                   /* pop ilvl up if applicable */
  237.           tok = ';';
  238.           continue;
  239.  
  240.         case '(' :                      /* may be condition start */
  241.           ++ plvl;
  242.           if ( isalnum ( oldtok )
  243.                 || isop ( oldtok ))
  244.             outb ( ' ' );
  245.           outs ( bfr );
  246.           tok = '(';
  247.           continue;
  248.  
  249.         case ')' :                      /* may be condition end */
  250.           -- plvl;
  251.           if ( isalnum ( oldtok ))
  252.             outb ( ' ' );
  253.           outs ( bfr );
  254.           tok = ')';
  255.           if ( iflg && ( iflg == plvl ))
  256.             { iflg = 0;                 /* end of condition */
  257.               tok = ';';                /* so fake statement end */
  258.             }
  259.           continue;
  260.  
  261.         case ':' :                      /* may be end of label */
  262.           outb ( ' ' );
  263.           outs ( bfr );
  264.           tok = ':';
  265.           if ( cflg )                   /* case or default label */
  266.             { tok = ';';                /* will force \n after comments */
  267.               ++ ilvl;
  268.               cflg = 0;
  269.             }
  270.           continue;
  271.  
  272.         case ';' :                      /* may be end of statement */
  273.           ind ( ilvl );
  274.           outs ( bfr );
  275.           if ( iflg && ( plvl != iflg ))
  276.             outb ( ' ' );               /* inside "for" condition */
  277.           else                          /* not in a "for" */
  278.             popilvl ();                 /* pop back up if ready */
  279.           dflg = 0;
  280.           continue;
  281.  
  282.         case ',' :                      /* list separator */
  283.           outs ( bfr );
  284.           if ( dflg )                   /* inside a declaration list */
  285.             outb ( '\n' ), ind ( 2 );
  286.           else                          /* elsewhere */
  287.             outb ( ' ' );
  288.           continue;
  289.  
  290.         case '#' :                      /* preprocessor flag */
  291. /*        if ( col )                    /* shouldn't happen */
  292. /*          outs ( bfr );       */
  293. /*        else                          /* handle preprocessor line */
  294.           dopp ( inf );
  295.           continue;
  296.  
  297.         case 'A' :                      /* keyword or identifier */
  298.           if ( indf )
  299.             { nl ();
  300.               tok = 'A';
  301.               indf = 0;
  302.             }
  303.  
  304.         case '0' :                      /* numeric string */
  305.  
  306.         case 'C' :                      /* char constant */
  307.  
  308.         case 'S' :                      /* string constant */
  309.           svtok = tok;
  310.           if (( tok == 'A' )
  311.                 && kwd ()
  312.                 && ( ! dflg )
  313.                 && ( col > ( ppilv + ilvl ) * lindv ))
  314.             nl ();
  315.           if ( oldtok && ( oldtok != ' ' ))
  316.             outb ( ' ' );
  317.           break;
  318.  
  319.         default :                       /* operators, etc. */
  320.           if ( tok & 128 )
  321.             { outb ( tok );             /* escaped chars ignored */
  322.               tok = svtok;
  323.               continue;
  324.             }
  325.           svtok = tok;
  326.           if ( isop ( svtok ) && ! isop ( oldtok ))
  327.             outb ( ' ' );
  328.           break;
  329.         }
  330.       ind ( ilvl );
  331.       if ( indf )                       /* push ilvl in */
  332.         { istk [ ++ istkp ] = (( ilvl ++ ) << 8 ) | ( clvl & 255 );
  333.           if ( iflg )
  334.             indf = 0;
  335.         }
  336.       if ( isalnum ( oldtok )
  337.             && ! ( isalnum ( svtok )
  338.             || isop ( svtok )))
  339.         outb ( ' ' );
  340.       outs ( bfr );
  341.       tok = svtok;
  342.       if ( tok == oldtok )
  343.         outb ( ' ' );
  344.     }
  345.   nl ();
  346.   outb ( '/' );                         /* trailer comment */
  347.   outs ( "* end of " );
  348.   outs ( fn );
  349.   outs ( " *" );
  350.   outb ( '/' );
  351.   nl ();
  352. }
  353.  
  354. poll ()                                 /* break or pause */
  355. #ifdef CPM
  356.   { int c ;
  357.     if (( c = bdos ( 6, 255 )) == 3 )     /* check for BREAK */
  358.       exit ( 7 );
  359.     if ( c )                              /* check for PAUSE */
  360.       { msg ( "<<PAUSED>>" );
  361.         while ( bdos ( 6, 255 ) != ' ' )
  362.           ;                               /* wait for SPACE */
  363.         msg ( "\b\b\b\b\b\b\b\b\b\b" );
  364.       }
  365.   }
  366. #else
  367.   {                                       /* empty for MSDOS */
  368.   }
  369. #endif
  370.  
  371. dopp ( fd )                             /* handle preprocessor lines */
  372. FILE * fd;
  373. { int asmflg;
  374.   tok = gtok ( fd );
  375.   if ( tok == 'A' )                     /* keyword at start of line */
  376.     { if ( ! strcmp ( bfr, "asm" ))
  377.         { if ( col )
  378.             nl ();
  379.           asmflg = 0;
  380. /*        ind ( 0 );    */
  381.           outb ( '#' );
  382.           outs ( bfr );
  383.           do                            /* just echo until #endasm */
  384.             {
  385.               tok = getc ( fd );
  386.               outb ( tok );
  387.               switch ( tok )
  388.                 { case '#':
  389.     if (asmflg == 0)
  390.                       ++asmflg;
  391.                     else
  392.                       asmflg = 0;
  393.                     break;
  394.                   case 'e':
  395.                     if (asmflg == 1)
  396.                       ++asmflg;
  397.     else
  398.                       asmflg = 0;
  399.     break;
  400.                   case 'n':
  401.                     if (asmflg == 2)
  402.                       ++asmflg;
  403.                     else
  404.                       asmflg = 0;
  405.                     break;
  406.                   case 'd':
  407.                     if (asmflg == 3)
  408.                       ++asmflg;
  409.                     else
  410.                       asmflg = 0;
  411.                     break;
  412.                   case 'a':
  413.                     if (asmflg == 4)
  414.                       ++asmflg;
  415.     else
  416.                       asmflg = 0;
  417.                     break;
  418.                   case 's':
  419.                     if (asmflg == 5)
  420.                       ++asmflg;
  421.                     else
  422.                       asmflg = 0;
  423.                     break;
  424.                   case 'm':
  425.                     if (asmflg == 6)
  426.                       ++asmflg;
  427.                     else
  428.       asmflg = 0;
  429.                     break;
  430.                   default:
  431.                     asmflg = 0;
  432.                 }
  433.             }
  434.           while ( asmflg != 7 )
  435.             ;
  436.         }
  437.       else
  438.         if ( bfr [ 0 ] == 'i' && bfr [ 1 ] == 'f' )
  439.           { ppkw ( 0 );
  440.             ppilv ++ ;
  441.           }
  442.       else
  443.         if ( ! strcmp ( bfr, "else" ))
  444.           ppkw ( - 1 );
  445.       else
  446.         if ( ! strcmp ( bfr, "endif" ))
  447.           { -- ppilv;
  448.             ppkw ( 0 );
  449.           }
  450.       else                              /* all other keywords */
  451.         ppkw ( 0 );
  452.     }
  453.   else                                  /* no keyword after the '#' */
  454.     ppkw ( 0 );
  455.   while ( tok = gtok ( fd ))            /* process rest of line here */
  456.     outs ( bfr );                       /* output without change */
  457.   nl ();
  458.   tok = 0;                              /* tell main scanner it was a newline */
  459. }
  460.  
  461. ppkw ( n )                              /* indent preprocessor line */
  462. int n ;
  463. { if ( col )                            /* force newline if needed */
  464.     nl ();
  465. /*  ind ( n );                          /* only to preprocessor level */
  466.   outb ( '#' );                         /* output the '#' */
  467.   outs ( bfr );                         /* output the keyword */
  468. }
  469.  
  470. gtok ( fd )                             /* input scanner */
  471. FILE * fd;
  472. { int c ;
  473.   char * p;
  474.   poll ();                              /* check for pause or break */
  475.   p = bfr;
  476.   * p ++ = c = esc ( fd );              /* save char in buffer */
  477.   * p = 0;
  478.   if ( c == '\n' )                      /* newline */
  479.     return ( 0 );
  480.   if ( isspace ( c ) || c == '\r' )     /* whitespace */
  481.     return ( ' ' );
  482.   if ( c < ' ' )                        /* any other control char */
  483.     return ( EOF );
  484.   if ( c == '/' )                       /* comment? */
  485.     { if (( c = esc ( fd )) != '*' )
  486.         { ungetc ( c, fd );             /* nope */
  487.           c = '/';
  488.         }
  489.       else                              /* yep, echo it all */
  490.         {
  491.           if ( col )
  492.             ind ( ccv / lindv );
  493.           outb ( '/' );
  494.           outb ( '*' );
  495.           while ( 1 )
  496.             { while (( c = esc ( fd )) != '*' )
  497.                 outb ( c );
  498.               outb ( '*' );
  499.               if (( c = esc ( fd )) == '/' )
  500. { outb ( '/' );
  501.                   return ( oldtok != ';' ? 0 : ' ' );
  502.                 }
  503.               else
  504.                 outb ( c );
  505.             }
  506.         }
  507.     }
  508.   if ( isalpha ( c ) || c == '_' )      /* keyword or identifier */
  509.     { while ( c = esc ( fd ), isalnum ( c )
  510.             || c == '_' )
  511.         * p ++ = c;
  512.       * p = 0;
  513.       ungetc ( c, fd );
  514.       return ( 'A' );
  515.     }
  516.   if ( isdigit ( c ))                   /* numeric constant */
  517.     { if ( c == '0' )                   /* octal or hex */
  518.         { c = esc ( fd );               /* check flag char */
  519.           if ( toupper ( c ) != 'X' )   /* then was not hex */
  520.             ungetc ( c, fd );           /* put it back */
  521.           else
  522.             { *
  523.                 p ++ = c;               /* save hex flag */
  524.               while ( c = esc ( fd ), ishex ( c ))
  525.                 * p ++ = c;
  526.               * p = 0;
  527.               ungetc ( c, fd );
  528.               return ( '0' );           /* and get out */
  529.             }
  530.         }
  531.       while ( c = esc ( fd ), isdigit ( c ))
  532.         * p ++ = c;
  533.       * p = 0;
  534.       ungetc ( c, fd );
  535.       return ( '0' );
  536.     }
  537.   if ( c == '\"' )                      /* string constant */
  538.     { while ( c = esc ( fd ), c != '\"' )
  539.         * p ++ = c;
  540.       * p ++ = c;
  541.       * p = 0;
  542.       return ( 'S' );
  543.     }
  544.   if ( c == '\'' )                      /* char constant */
  545.     { while ( c = esc ( fd ), c != '\'' )
  546.         * p ++ = c;
  547.       * p ++ = c;
  548.       * p = 0;
  549.       return ( 'C' );
  550.     }
  551.   * p = 0;                              /* anything else */
  552.   return ( c );
  553. }
  554.  
  555. outs ( s )                              /* output string */
  556. char * s;
  557. { if ( col + strlen ( s ) > lnwv )
  558.     outb ( 128 + '\n' );
  559.   while ( * s )
  560.     outb ( * s ++ );
  561. }
  562.  
  563. outb ( c )                              /* output byte */
  564. char c ;
  565. { if ( c & 128 )                        /* ESC sequence */
  566.     { outb ( '\\' );
  567.       c &= 127;
  568.     }
  569.   switch ( c )                          /* special treatment */
  570.     {
  571.     case '\t' :                         /* machine tab */
  572.       col = nxtb ( col );
  573.       tok = ' ';
  574.       out ( c );
  575.       c = 0;
  576.       break;
  577.  
  578.     case '\n' :                         /* newline */
  579.       ln += 1;
  580.       out ( c );
  581.       if ( nval )                       /* line number */
  582.         outf ( ln * nval );
  583.  
  584.     case '\r' :                         /* CR */
  585.       c = col = 0;
  586.       break;
  587.  
  588.     case ' ' :                          /* blank */
  589.       tok = ' ';
  590.  
  591.     default :                           /* anything else */
  592.       if ( c >= ' ' )                   /* printable */
  593.         { if ( ++ col > lnwv )          /* check for wrap */
  594.             { col = 0;
  595.               outb ( 128 + '\n' );      /* force cont line */
  596.             }
  597.         }
  598.       else                              /* control, skip it */
  599.         c = 0;
  600.       break;
  601.     }
  602.   if ( c )
  603.     out ( c );                          /* send char out */
  604. }
  605.  
  606. out ( c )                               /*byte output*/
  607. char c ;
  608. { poll ();
  609.   fprintf ( otf, "%c", c );
  610. }
  611.  
  612. outf ( n )                              /*line number output*/
  613. int n ;
  614. { fprintf ( otf, "%d\t", n );
  615. }
  616.  
  617. msg ( s )                               /* output string to CRT */
  618. char * s;
  619. { poll ();
  620.   while ( * s )
  621.     tocrt ( * s ++ );
  622. }
  623.  
  624. tocrt ( c )                             /* output char to CRT */
  625. char c ;
  626. #ifdef CPM
  627.   { if ( c == '\n' )
  628.       bdos ( 6, 13 );
  629.     bdos ( 6, c & 255 );                  /* use BDOS for CPM */
  630.   }
  631. #else
  632.   { fputc ( c, stderr );                  /* use DOS for MSDOS */
  633.   }
  634. #endif
  635.  
  636. nl ()                                   /* newline */
  637. { outb ( '\n' );
  638.   tok = 0;
  639. }
  640.  
  641. ind ( n )                               /* do indenting */
  642. int n ;
  643. { int svtok ;
  644.   svtok = tok;                          /* save "tok" past the indent */
  645.   n += ppilv;                           /* include preprocessor indent */
  646.   n *= lindv;
  647.   while ( nxtb ( col ) <= n )           /* machine tab if possible */
  648.     outb ( '\t' );
  649.   while ( col < n )                     /* then fill with spaces */
  650.     outb ( ' ' );
  651.   tok = svtok;                          /* restore "tok" */
  652. }
  653.  
  654. nxtb ( n )                              /* return next tabstop */
  655. int n ;
  656. { return ( n + ( mtabv - n % mtabv ));
  657. }
  658.  
  659. int inchr = '\n';                       /* last input character */
  660.  
  661. esc ( fd )                              /* handle ESC chars */
  662. FILE * fd;
  663. { if ( inchr == '\n' )                  /* if at start of line */
  664.     { inchr = getc ( fd );
  665.       if ( isdigit ( inchr ))
  666.         { while ( inchr = getc ( fd ), isdigit ( inchr ))
  667.             ;                           /* smash line numbers */
  668.           while ( isspace ( inchr ))
  669.             inchr = getc ( fd );        /* and trailing whitespace */
  670.         }
  671.     }
  672.   else
  673.     inchr = getc ( fd );                /* get next input char */
  674.   if ( inchr != '\\' )
  675.     return ( inchr );                   /* normal char */
  676.   return ( inchr = ( getc ( fd ) | 128 ));/* ESC, flag next */
  677. }
  678.  
  679. popilvl ()                              /* pop ilvl out */
  680. { while ( clvl == ( istk [ istkp ] & 255 ))
  681.     { ilvl = 255 & ( istk [ istkp -- ] >> 8 );
  682.       if ( istkp < 0 )
  683.         { istkp = 0;
  684.           return;
  685.         }
  686.     }
  687. }
  688.  
  689. kwd ()                                  /* check for keyword */
  690. { if ( ! ( strcmp ( bfr, "break" ))
  691.         || ! ( strcmp ( bfr, "continue" ))
  692.         || ! ( strcmp ( bfr, "return" )))
  693.     return ( YES );                     /* ordinary keywords */
  694.   if ( ! ( strcmp ( bfr, "case" ))
  695.         || ! ( strcmp ( bfr, "default" )))
  696.     { outb ( '\n' );
  697.       ++ cflg;
  698.       -- ilvl;
  699.       return ( YES );                   /* only inside switch() */
  700.     }
  701.   if ( ! ( strcmp ( bfr, "char" ))
  702.         || ! ( strcmp ( bfr, "double" ))
  703.         || ! ( strcmp ( bfr, "extern" ))
  704.         || ! ( strcmp ( bfr, "float" ))
  705.         || ! ( strcmp ( bfr, "int" ))
  706.         || ! ( strcmp ( bfr, "static" )))
  707.     { ++ dflg;
  708.       return ( YES );                   /* declarations */
  709.     }
  710.   if ( ! ( strcmp ( bfr, "do" ))
  711.         || ! ( strcmp ( bfr, "else" )))
  712.     { ++ indf;
  713.       return ( YES );                   /* indent but no parens */
  714.     }
  715.   if ( ! ( strcmp ( bfr, "for" ))
  716.         || ! ( strcmp ( bfr, "if" ))
  717.         || ! ( strcmp ( bfr, "switch" ))
  718.         || ! ( strcmp ( bfr, "while" )))
  719.     { iflg = plvl;
  720.       ++ indf;
  721.       return ( YES );                   /* indent with parens */
  722.     }
  723.   return ( NO );                        /* not a keyword */
  724. }
  725.  
  726. isop ( t )                              /* return YES if t is operator */
  727. int t ;
  728. { if (( ! oldtok ) || oldtok == ' ' )
  729.     return ( NO );                      /* force NO if first nonblank */
  730.   return ( index ( "+-/!*^?~=<>&|", t ) ? YES : NO );
  731. }
  732.  
  733. /* end of CB3.C */
  734.